package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.service.OrderService;
import com.dongdongshop.uitl.JwtUtil;
import com.dongdongshop.vo.TradeVo;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService os;

    @Autowired
    private JwtUtil jwtUtil;
    //提交订单
    @PostMapping("submitOrder")
    public Result submitOrder(@RequestHeader String AutharizeToken, @RequestParam Long addressId,@RequestParam String payType){
        TradeVo tradeVo = os.submitOrder(AutharizeToken, addressId, payType);
        return Result.OK().setData(tradeVo);
    }

    @PostMapping("getAll")
    public Result getAll(@RequestHeader String AutharizeToken){
//    public Result addCart(@RequestParam Long itemId,@RequestParam Integer num){

        Claims claims = jwtUtil.parseJwt(AutharizeToken);
        String userId = claims.getId();//登录用户的id
        return Result.OK().setData(os.getAll(userId));
    }
}
